import React, {
  PureComponent,
  Fragment
} from 'react'
import {BASEURL,GETHEADERS,POSTHEADERS} from '../../api'
import {getReq,postReq} from 'network-request-bywhj'
import {transferDatas} from 'js-fun-bywhj'
class Index extends PureComponent{
  constructor(props, context) {
    super(props, context);
    this.state = {
      userName:"root",
      password:"root"
    }
  }
  render() {
    return (
        <Fragment>
          <h1>登录</h1>
          <input
              placeholder={"用户名"}
              onChange={this.changeName.bind(this)}
              value={this.state.userName}
          />
          <br/><br/>
          <input
              placeholder={"密码"}
              onChange={this.changePassword.bind(this)}
              type={"password"}
              value={this.state.password}
          />
          <br/><br/>
          <button onClick={this.login.bind(this)}>登录</button>
        </Fragment>
    )
  }
  login(){
    postReq(`${BASEURL}/homework/homework/login`, POSTHEADERS, transferDatas('', {
    // postReq(`${BASEURL}/homework/login`, POSTHEADERS, transferDatas('', {
      username: this.state.userName,
      password: this.state.password
    }, 'post'), (responseData) => {
      console.log(responseData);
      if(responseData.status === "ok"){
        this.props.history.push('/')
      }
    })
  }
  changeName(e){
    this.setState({
      userName:e.target.value
    })
  }
  changePassword(e){
    this.setState({
      password:e.target.value
    })
  }
  componentDidMount(){

  };
}
export default Index
